package com.ruoyi.job.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.business.waterManagement.WrStationR;
import com.ruoyi.common.core.domain.business.waterManagement.WrStatvolD;
import com.ruoyi.common.core.domain.business.waterManagement.WrStatvolH;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.job.mapper.WrStationRMapper;
import com.ruoyi.job.mapper.WrStatvolDMapper;
import com.ruoyi.job.service.IWrStationRService;
import com.ruoyi.job.service.IWrStatvolDService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;


/**
 * 测站日水量Service业务层处理
 * 
 * @author hwd
 * @date 2023-02-20
 */
@Service
public class WrStatvolDServiceImpl extends ServiceImpl<WrStatvolDMapper, WrStatvolD> implements IWrStatvolDService
{
    @Autowired
    private WrStatvolDMapper wrStatvolDMapper;

    /**
     * 查询测站日水量
     * 
     * @param statCd 测站日水量主键
     * @return 测站日水量
     */
    @Override
    public WrStatvolD selectWrStatvolDByStatCd(String statCd)
    {
        return wrStatvolDMapper.selectWrStatvolDByStatCd(statCd);
    }

    /**
     * 查询测站日水量列表
     * 
     * @param wrStatvolD 测站日水量
     * @return 测站日水量
     */
    @Override
    public List<WrStatvolD> selectWrStatvolDList(WrStatvolD wrStatvolD)
    {
        if (wrStatvolD.getStatDay()!=null){

        String [] strings= DateUtils.jsYmd(wrStatvolD.getStatDay());
        String yy =strings[0];
        String mm =strings[1];
        wrStatvolD.setYy(yy);
        wrStatvolD.setMm(mm);
        }
        return wrStatvolDMapper.selectWrStatvolDList(wrStatvolD);
    }

    /**
     * 新增测站日水量
     * 
     * @param wrStatvolD 测站日水量
     * @return 结果
     */
    @Override
    public int insertWrStatvolD(WrStatvolD wrStatvolD)
    {
        return wrStatvolDMapper.insertWrStatvolD(wrStatvolD);
    }

    /**
     * 修改测站日水量
     * 
     * @param wrStatvolD 测站日水量
     * @return 结果
     */
    @Override
    public int updateWrStatvolD(WrStatvolD wrStatvolD)
    {
        return wrStatvolDMapper.updateWrStatvolD(wrStatvolD);
    }

    /**
     * 批量删除测站日水量
     * 
     * @param statCds 需要删除的测站日水量主键
     * @return 结果
     */
    @Override
    public int deleteWrStatvolDByStatCds(String[] statCds)
    {
        return wrStatvolDMapper.deleteWrStatvolDByStatCds(statCds);
    }

    /**
     * 删除测站日水量信息
     * 
     * @param statCd 测站日水量主键
     * @return 结果
     */
    @Override
    public int deleteWrStatvolDByStatCd(String statCd)
    {
        return wrStatvolDMapper.deleteWrStatvolDByStatCd(statCd);
    }

    @Override
    public WrStatvolD countMonthByWrStatvolD(String statCd,Date day) {
            String[] strings = DateUtils.jsYmd(day);
            String yy = strings[0];
            String mm = strings[1];
        return wrStatvolDMapper.countMonthByWrStatvolD(statCd,yy,mm);
    }

    @Override
    public void insertOrUpdateWrStatvolD(WrStatvolH wrStatvolH) {
        WrStatvolD saveWrStatvolD =new WrStatvolD();
        saveWrStatvolD.setStatCd(wrStatvolH.getStatCd());
        saveWrStatvolD.setDayLevel(wrStatvolH.getHourLevel());
        saveWrStatvolD.setDayFlow(wrStatvolH.getHourFlow());
        saveWrStatvolD.setDayVol(wrStatvolH.getHourVol());
        saveWrStatvolD.setStatDay(transferString2Date(wrStatvolH.getStatday()));
        wrStatvolDMapper.insertOrUpdateWrStatvolD(saveWrStatvolD);
    }

    @Override
    public WrStatvolD countWiOrgVolDByWrStatvolD(String statCd, Date day) {
        String[] strings = DateUtils.jsYmd(day);
        String yy = strings[0];
        String mm = strings[1];
        String dd = strings[2];
        return wrStatvolDMapper.countWiOrgVolDByWrStatvolD(statCd,yy,mm,dd);
    }

    public static Date transferString2Date(String s) {
        Date date = new Date();
        try {
            date = new SimpleDateFormat("yyyy-MM-dd").parse(s);
        } catch (ParseException e) {
            //LOGGER.error("时间转换错误, string = {}", s, e);
        }
        return date;
    }


}
